package com.wangzaiplus.test.designpattern.singleton;

/**懒汉式单例
 * @ClassName LazySingleton
 * @Description: TODO
 * @Author wgc
 * @Date 2020/06/17 9:50
 * @Version V1.0
 **/
public class LazySingleton {
    private static volatile  LazySingleton instance;//保证instance在多线程下可以被同步
    private LazySingleton(){}//避免被外部实例化
    public static synchronized  LazySingleton getInstance(){

        if(instance==null){
            instance=new LazySingleton();
        }
        return instance;
    }
    public static void main(String[] args){
        for (int i=0;i<100;i++){
            System.out.println(LazySingleton.getInstance());
        }

    }
}
